home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 22 / Cream of the Crop 22.iso / doom / quake1.zip / MONSEV10.ZIP / WEAPONS.QC < prev   
Text File  |  1996-09-02  |  26KB  |  1,235 lines

  1. /*
  2. */
  3. void (entity targ, entity inflictor, entity attacker, float damage) T_Damage;
  4. void () player_run;
  5. void(entity bomb, entity attacker, float rad, entity ignore) T_RadiusDamage;
  6. void(vector org, vector vel, float damage) SpawnBlood;
  7. void() SuperDamageSound;
  8.  
  9.  
  10. // called by worldspawn
  11. void() W_Precache =
  12. {
  13.     precache_sound ("weapons/r_exp3.wav");    // new rocket explosion
  14.     precache_sound ("weapons/rocket1i.wav");    // spike gun
  15.     precache_sound ("weapons/sgun1.wav");
  16.     precache_sound ("weapons/guncock.wav");    // player shotgun
  17.     precache_sound ("weapons/ric1.wav");    // ricochet (used in c code)
  18.     precache_sound ("weapons/ric2.wav");    // ricochet (used in c code)
  19.     precache_sound ("weapons/ric3.wav");    // ricochet (used in c code)
  20.     precache_sound ("weapons/spike2.wav");    // super spikes
  21.     precache_sound ("weapons/tink1.wav");    // spikes tink (used in c code)
  22.     precache_sound ("weapons/grenade.wav");    // grenade launcher
  23.     precache_sound ("weapons/bounce.wav");        // grenade bounce
  24.     precache_sound ("weapons/shotgn2.wav");    // super shotgun
  25. };
  26.  
  27. float() crandom =
  28. {
  29.     return 2*(random() - 0.5);
  30. };
  31.  
  32. /*
  33. ================
  34. W_FireAxe
  35. ================
  36. */
  37. void() W_FireAxe =
  38. {
  39.     local    vector    source;
  40.     local    vector    org;
  41.  
  42.     source = self.origin + '0 0 16';
  43.     traceline (source, source + v_forward*64, FALSE, self);
  44.     if (trace_fraction == 1.0)
  45.         return;
  46.     
  47.     org = trace_endpos - v_forward*4;
  48.  
  49.     if (trace_ent.takedamage)
  50.     {
  51.         trace_ent.axhitme = 1;
  52.         SpawnBlood (org, '0 0 0', 20);
  53.         T_Damage (trace_ent, self, self, 20);
  54.     }
  55.     else
  56.     {    // hit wall
  57.         sound (self, CHAN_WEAPON, "player/axhit2.wav", 1, ATTN_NORM);
  58.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  59.         WriteByte (MSG_BROADCAST, TE_GUNSHOT);
  60.         WriteCoord (MSG_BROADCAST, org_x);
  61.         WriteCoord (MSG_BROADCAST, org_y);
  62.         WriteCoord (MSG_BROADCAST, org_z);
  63.     }
  64. };
  65.  
  66.  
  67. //============================================================================
  68.  
  69.  
  70. vector() wall_velocity =
  71. {
  72.     local vector    vel;
  73.     
  74.     vel = normalize (self.velocity);
  75.     vel = normalize(vel + v_up*(random()- 0.5) + v_right*(random()- 0.5));
  76.     vel = vel + 2*trace_plane_normal;
  77.     vel = vel * 200;
  78.     
  79.     return vel;
  80. };
  81.  
  82.  
  83. /*
  84. ================
  85. SpawnMeatSpray
  86. ================
  87. */
  88. void(vector org, vector vel) SpawnMeatSpray =
  89. {
  90.     local    entity missile, mpuff;
  91.     local    vector    org;
  92.  
  93.     missile = spawn ();
  94.     missile.owner = self;
  95.     missile.movetype = MOVETYPE_BOUNCE;
  96.     missile.solid = SOLID_NOT;
  97.  
  98.     makevectors (self.angles);
  99.  
  100.     missile.velocity = vel;
  101.     missile.velocity_z = missile.velocity_z + 250 + 50*random();
  102.  
  103.     missile.avelocity = '3000 1000 2000';
  104.     
  105. // set missile duration
  106.     missile.nextthink = time + 1;
  107.     missile.think = SUB_Remove;
  108.  
  109.     setmodel (missile, "progs/zom_gib.mdl");
  110.     setsize (missile, '0 0 0', '0 0 0');        
  111.     setorigin (missile, org);
  112. };
  113.  
  114. /*
  115. ================
  116. SpawnBlood
  117. ================
  118. */
  119. void(vector org, vector vel, float damage) SpawnBlood =
  120. {
  121.     particle (org, vel*0.1, 73, damage*2);
  122. };
  123.  
  124. /*
  125. ================
  126. spawn_touchblood
  127. ================
  128. */
  129. void(float damage) spawn_touchblood =
  130. {
  131.     local vector    vel;
  132.  
  133.     vel = wall_velocity () * 0.2;
  134.     SpawnBlood (self.origin + vel*0.01, vel, damage);
  135. };
  136.  
  137.  
  138. /*
  139. ================
  140. SpawnChunk
  141. ================
  142. */
  143. void(vector org, vector vel) SpawnChunk =
  144. {
  145.     particle (org, vel*0.02, 0, 10);
  146. };
  147.  
  148. /*
  149. ==============================================================================
  150.  
  151. MULTI-DAMAGE
  152.  
  153. Collects multiple small damages into a single damage
  154.  
  155. ==============================================================================
  156. */
  157.  
  158. entity    multi_ent;
  159. float    multi_damage;
  160.  
  161. void() ClearMultiDamage =
  162. {
  163.     multi_ent = world;
  164.     multi_damage = 0;
  165. };
  166.  
  167. void() ApplyMultiDamage =
  168. {
  169.     if (!multi_ent)
  170.         return;
  171.     T_Damage (multi_ent, self, self, multi_damage);
  172. };
  173.  
  174. void(entity hit, float damage) AddMultiDamage =
  175. {
  176.     if (!hit)
  177.         return;
  178.     
  179.     if (hit != multi_ent)
  180.     {
  181.         ApplyMultiDamage ();
  182.         multi_damage = damage;
  183.         multi_ent = hit;
  184.     }
  185.     else
  186.         multi_damage = multi_damage + damage;
  187. };
  188.  
  189. /*
  190. ==============================================================================
  191.  
  192. BULLETS
  193.  
  194. ==============================================================================
  195. */
  196.  
  197. /*
  198. ================
  199. TraceAttack
  200. ================
  201. */
  202. void(float damage, vector dir) TraceAttack =
  203. {
  204.     local    vector    vel, org;
  205.     
  206.     vel = normalize(dir + v_up*crandom() + v_right*crandom());
  207.     vel = vel + 2*trace_plane_normal;
  208.     vel = vel * 200;
  209.  
  210.     org = trace_endpos - dir*4;
  211.  
  212.     if (trace_ent.takedamage)
  213.     {
  214.         SpawnBlood (org, vel*0.2, damage);
  215.         AddMultiDamage (trace_ent, damage);
  216.     }
  217.     else
  218.     {
  219.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  220.         WriteByte (MSG_BROADCAST, TE_GUNSHOT);
  221.         WriteCoord (MSG_BROADCAST, org_x);
  222.         WriteCoord (MSG_BROADCAST, org_y);
  223.         WriteCoord (MSG_BROADCAST, org_z);
  224.     }
  225. };
  226.  
  227. /*
  228. ================
  229. FireBullets
  230.  
  231. Used by shotgun, super shotgun, and enemy soldier firing
  232. Go to the trouble of combining multiple pellets into a single damage call.
  233. ================
  234. */
  235. void(float shotcount, vector dir, vector spread) FireBullets =
  236. {
  237.     local    vector direction;
  238.     local    vector    src;
  239.     
  240.     makevectors(self.v_angle);
  241.  
  242.     src = self.origin + v_forward*10;
  243.     src_z = self.absmin_z + self.size_z * 0.7;
  244.  
  245.     ClearMultiDamage ();
  246.     while (shotcount > 0)
  247.     {
  248.         direction = dir + crandom()*spread_x*v_right + crandom()*spread_y*v_up;
  249.  
  250.         traceline (src, src + direction*2048, FALSE, self);
  251.         if (trace_fraction != 1.0)
  252.             TraceAttack (4, direction);
  253.  
  254.         shotcount = shotcount - 1;
  255.     }
  256.     ApplyMultiDamage ();
  257. };
  258.  
  259. /*
  260. ================
  261. W_FireShotgun
  262. ================
  263. */
  264. void() W_FireShotgun =
  265. {
  266.     local vector dir;
  267.  
  268.     sound (self, CHAN_WEAPON, "weapons/guncock.wav", 1, ATTN_NORM);    
  269.  
  270.     self.punchangle_x = -2;
  271.     
  272.     self.currentammo = self.ammo_shells = self.ammo_shells - 1;
  273.     dir = aim (self, 100000);
  274.     FireBullets (6, dir, '0.04 0.04 0');
  275. };
  276.  
  277.  
  278. /*
  279. ================
  280. W_FireSuperShotgun
  281. ================
  282. */
  283. void() W_FireSuperShotgun =
  284. {
  285.     local vector dir;
  286.  
  287.     if (self.currentammo == 1)
  288.     {
  289.         W_FireShotgun ();
  290.         return;
  291.     }
  292.         
  293.     sound (self ,CHAN_WEAPON, "weapons/shotgn2.wav", 1, ATTN_NORM);    
  294.  
  295.     self.punchangle_x = -4;
  296.     
  297.     self.currentammo = self.ammo_shells = self.ammo_shells - 2;
  298.     dir = aim (self, 100000);
  299.     FireBullets (14, dir, '0.14 0.08 0');
  300. };
  301.  
  302.  
  303. /*
  304. ==============================================================================
  305.  
  306. ROCKETS
  307.  
  308. ==============================================================================
  309. */
  310.  
  311. void()    s_explode1    =    [0,        s_explode2] {};
  312. void()    s_explode2    =    [1,        s_explode3] {};
  313. void()    s_explode3    =    [2,        s_explode4] {};
  314. void()    s_explode4    =    [3,        s_explode5] {};
  315. void()    s_explode5    =    [4,        s_explode6] {};
  316. void()    s_explode6    =    [5,        SUB_Remove] {};
  317.  
  318. void() BecomeExplosion =
  319. {
  320.     self.movetype = MOVETYPE_NONE;
  321.     self.velocity = '0 0 0';
  322.     self.touch = SUB_Null;
  323.     setmodel (self, "progs/s_explod.spr");
  324.     self.solid = SOLID_NOT;
  325.     s_explode1 ();
  326. };
  327.  
  328. void() T_MissileTouch =
  329. {
  330.     local float    damg;
  331.  
  332.     if (other == self.owner)
  333.         return;        // don't explode on owner
  334.  
  335.     if (pointcontents(self.origin) == CONTENT_SKY)
  336.     {
  337.         remove(self);
  338.         return;
  339.     }
  340.  
  341.     damg = 100 + random()*20;
  342.     
  343.     if (other.health)
  344.     {
  345.         if (other.classname == "monster_shambler")
  346.             damg = damg * 0.5;    // mostly immune
  347.         T_Damage (other, self, self.owner, damg );
  348.     }
  349.  
  350.     // don't do radius damage to the other, because all the damage
  351.     // was done in the impact
  352.     T_RadiusDamage (self, self.owner, 120, other);
  353.  
  354. //    sound (self, CHAN_WEAPON, "weapons/r_exp3.wav", 1, ATTN_NORM);
  355.     self.origin = self.origin - 8*normalize(self.velocity);
  356.  
  357.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  358.     WriteByte (MSG_BROADCAST, TE_EXPLOSION);
  359.     WriteCoord (MSG_BROADCAST, self.origin_x);
  360.     WriteCoord (MSG_BROADCAST, self.origin_y);
  361.     WriteCoord (MSG_BROADCAST, self.origin_z);
  362.  
  363.     BecomeExplosion ();
  364. };
  365.  
  366.  
  367.  
  368. /*
  369. ================
  370. W_FireRocket
  371. ================
  372. */
  373. void() W_FireRocket =
  374. {
  375.     local    entity missile, mpuff;
  376.     
  377.     self.currentammo = self.ammo_rockets = self.ammo_rockets - 1;
  378.     
  379.     sound (self, CHAN_WEAPON, "weapons/sgun1.wav", 1, ATTN_NORM);
  380.  
  381.     self.punchangle_x = -2;
  382.  
  383.     missile = spawn ();
  384.     missile.owner = self;
  385.     missile.movetype = MOVETYPE_FLYMISSILE;
  386.     missile.solid = SOLID_BBOX;
  387.         
  388. // set missile speed    
  389.  
  390.     makevectors (self.v_angle);
  391.     missile.velocity = aim(self, 1000);
  392.     missile.velocity = missile.velocity * 1000;
  393.     missile.angles = vectoangles(missile.velocity);
  394.     
  395.     missile.touch = T_MissileTouch;
  396.     
  397. // set missile duration
  398.     missile.nextthink = time + 5;
  399.     missile.think = SUB_Remove;
  400.  
  401.     setmodel (missile, "progs/missile.mdl");
  402.     setsize (missile, '0 0 0', '0 0 0');        
  403.     setorigin (missile, self.origin + v_forward*8 + '0 0 16');
  404. };
  405.  
  406. /*
  407. ===============================================================================
  408.  
  409. LIGHTNING
  410.  
  411. ===============================================================================
  412. */
  413.  
  414. /*
  415. =================
  416. LightningDamage
  417. =================
  418. */
  419. void(vector p1, vector p2, entity from, float damage) LightningDamage =
  420. {
  421.     local entity        e1, e2;
  422.     local vector        f;
  423.     
  424.     f = p2 - p1;
  425.     normalize (f);
  426.     f_x = 0 - f_y;
  427.     f_y = f_x;
  428.     f_z = 0;
  429.     f = f*16;
  430.  
  431.     e1 = e2 = world;
  432.  
  433.     traceline (p1, p2, FALSE, self);
  434.     if (trace_ent.takedamage)
  435.     {
  436.         particle (trace_endpos, '0 0 100', 225, damage*4);
  437.         T_Damage (trace_ent, from, from, damage);
  438.         if (self.classname == "player")
  439.         {
  440.             if (other.classname == "player")
  441.                 trace_ent.velocity_z = trace_ent.velocity_z + 400;
  442.         }
  443.     }
  444.     e1 = trace_ent;
  445.  
  446.     traceline (p1 + f, p2 + f, FALSE, self);
  447.     if (trace_ent != e1 && trace_ent.takedamage)
  448.     {
  449.         particle (trace_endpos, '0 0 100', 225, damage*4);
  450.         T_Damage (trace_ent, from, from, damage);
  451.     }
  452.     e2 = trace_ent;
  453.  
  454.     traceline (p1 - f, p2 - f, FALSE, self);
  455.     if (trace_ent != e1 && trace_ent != e2 && trace_ent.takedamage)
  456.     {
  457.         particle (trace_endpos, '0 0 100', 225, damage*4);
  458.         T_Damage (trace_ent, from, from, damage);
  459.     }
  460. };
  461.  
  462.  
  463. void() W_FireLightning =
  464. {
  465.     local    vector        org;
  466.  
  467.     if (self.ammo_cells < 1)
  468.     {
  469.         self.weapon = W_BestWeapon ();
  470.         W_SetCurrentAmmo ();
  471.         return;
  472.     }
  473.  
  474. // explode if under water
  475.     if (self.waterlevel > 1)
  476.     {
  477.         T_RadiusDamage (self, self, 35*self.ammo_cells, world);
  478.         self.ammo_cells = 0;
  479.         W_SetCurrentAmmo ();
  480.         return;
  481.     }
  482.  
  483.     if (self.t_width < time)
  484.     {
  485.         sound (self, CHAN_WEAPON, "weapons/lhit.wav", 1, ATTN_NORM);
  486.         self.t_width = time + 0.6;
  487.     }
  488.     self.punchangle_x = -2;
  489.  
  490.     self.currentammo = self.ammo_cells = self.ammo_cells - 1;
  491.  
  492.     org = self.origin + '0 0 16';
  493.     
  494.     traceline (org, org + v_forward*600, TRUE, self);
  495.  
  496.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  497.     WriteByte (MSG_BROADCAST, TE_LIGHTNING2);
  498.     WriteEntity (MSG_BROADCAST, self);
  499.     WriteCoord (MSG_BROADCAST, org_x);
  500.     WriteCoord (MSG_BROADCAST, org_y);
  501.     WriteCoord (MSG_BROADCAST, org_z);
  502.     WriteCoord (MSG_BROADCAST, trace_endpos_x);
  503.     WriteCoord (MSG_BROADCAST, trace_endpos_y);
  504.     WriteCoord (MSG_BROADCAST, trace_endpos_z);
  505.  
  506.     LightningDamage (self.origin, trace_endpos + v_forward*4, self, 30);
  507. };
  508.  
  509.  
  510. //=============================================================================
  511.  
  512.  
  513. void() GrenadeExplode =
  514. {
  515.         if (avoidtarget == self)        //SCC.  Nullify avoidtarget if
  516.                 avoidtarget = world;    //it is the exploding grenade.
  517.  
  518.         T_RadiusDamage (self, self.owner, 120, world);
  519.  
  520.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  521.     WriteByte (MSG_BROADCAST, TE_EXPLOSION);
  522.     WriteCoord (MSG_BROADCAST, self.origin_x);
  523.     WriteCoord (MSG_BROADCAST, self.origin_y);
  524.     WriteCoord (MSG_BROADCAST, self.origin_z);
  525.  
  526.     BecomeExplosion ();
  527.  
  528. };
  529.  
  530. void() GrenadeTouch =
  531. {
  532.     if (other == self.owner)
  533.         return;        // don't explode on owner
  534.     if (other.takedamage == DAMAGE_AIM)
  535.     {
  536.         GrenadeExplode();
  537.         return;
  538.     }
  539.     sound (self, CHAN_WEAPON, "weapons/bounce.wav", 1, ATTN_NORM);    // bounce sound
  540.  
  541.         avoidtarget = self;   //SCC. The grenade is now avoidtarget.
  542.  
  543.         self.enemy = self.owner;         //SCC. Make sure nearby monsters
  544.         sight_entity = self;             //will become aware of the     
  545.         sight_entity_time = time;        //bouncing grenade and get angry
  546.         self.show_hostile = time + 1;    //at the jerk who launched it.
  547.  
  548.     if (self.velocity == '0 0 0')
  549.                 self.avelocity = '0 0 0';
  550.  
  551. };
  552.  
  553. /*
  554. ================
  555. W_FireGrenade
  556. ================
  557. */
  558. void() W_FireGrenade =
  559. {
  560.     local    entity missile, mpuff;
  561.     
  562.     self.currentammo = self.ammo_rockets = self.ammo_rockets - 1;
  563.     
  564.     sound (self, CHAN_WEAPON, "weapons/grenade.wav", 1, ATTN_NORM);
  565.  
  566.     self.punchangle_x = -2;
  567.  
  568.     missile = spawn ();
  569.     missile.owner = self;
  570.     missile.movetype = MOVETYPE_BOUNCE;
  571.     missile.solid = SOLID_BBOX;
  572.     missile.classname = "grenade";
  573.  
  574. // set missile speed    
  575.  
  576.     makevectors (self.v_angle);
  577.  
  578.     if (self.v_angle_x)
  579.         missile.velocity = v_forward*600 + v_up * 200 + crandom()*v_right*10 + crandom()*v_up*10;
  580.     else
  581.     {
  582.         missile.velocity = aim(self, 10000);
  583.         missile.velocity = missile.velocity * 600;
  584.         missile.velocity_z = 200;
  585.     }
  586.  
  587.     missile.avelocity = '300 300 300';
  588.  
  589.     missile.angles = vectoangles(missile.velocity);
  590.     
  591.     missile.touch = GrenadeTouch;
  592.     
  593. // set missile duration
  594.     missile.nextthink = time + 2.5;
  595.     missile.think = GrenadeExplode;
  596.  
  597.     setmodel (missile, "progs/grenade.mdl");
  598.     setsize (missile, '0 0 0', '0 0 0');        
  599.     setorigin (missile, self.origin);
  600. };
  601.  
  602.  
  603. //=============================================================================
  604.  
  605. void() spike_touch;
  606. void() superspike_touch;
  607.  
  608.  
  609. /*
  610. ===============
  611. launch_spike
  612.  
  613. Used for both the player and the ogre
  614. ===============
  615. */
  616. void(vector org, vector dir) launch_spike =
  617. {
  618.     newmis = spawn ();
  619.     newmis.owner = self;
  620.     newmis.movetype = MOVETYPE_FLYMISSILE;
  621.     newmis.solid = SOLID_BBOX;
  622.  
  623.     newmis.angles = vectoangles(dir);
  624.     
  625.     newmis.touch = spike_touch;
  626.     newmis.classname = "spike";
  627.     newmis.think = SUB_Remove;
  628.     newmis.nextthink = time + 6;
  629.     setmodel (newmis, "progs/spike.mdl");
  630.     setsize (newmis, VEC_ORIGIN, VEC_ORIGIN);        
  631.     setorigin (newmis, org);
  632.  
  633.     newmis.velocity = dir * 1000;
  634. };
  635.  
  636. void() W_FireSuperSpikes =
  637. {
  638.     local vector    dir;
  639.     local entity    old;
  640.     
  641.     sound (self, CHAN_WEAPON, "weapons/spike2.wav", 1, ATTN_NORM);
  642.     self.attack_finished = time + 0.2;
  643.     self.currentammo = self.ammo_nails = self.ammo_nails - 2;
  644.     dir = aim (self, 1000);
  645.     launch_spike (self.origin + '0 0 16', dir);
  646.     newmis.touch = superspike_touch;
  647.     setmodel (newmis, "progs/s_spike.mdl");
  648.     setsize (newmis, VEC_ORIGIN, VEC_ORIGIN);        
  649.     self.punchangle_x = -2;
  650. };
  651.  
  652. void(float ox) W_FireSpikes =
  653. {
  654.     local vector    dir;
  655.     local entity    old;
  656.     
  657.     makevectors (self.v_angle);
  658.     
  659.     if (self.ammo_nails >= 2 && self.weapon == IT_SUPER_NAILGUN)
  660.     {
  661.         W_FireSuperSpikes ();
  662.         return;
  663.     }
  664.  
  665.     if (self.ammo_nails < 1)
  666.     {
  667.         self.weapon = W_BestWeapon ();
  668.         W_SetCurrentAmmo ();
  669.         return;
  670.     }
  671.  
  672.     sound (self, CHAN_WEAPON, "weapons/rocket1i.wav", 1, ATTN_NORM);
  673.     self.attack_finished = time + 0.2;
  674.     self.currentammo = self.ammo_nails = self.ammo_nails - 1;
  675.     dir = aim (self, 1000);
  676.     launch_spike (self.origin + '0 0 16' + v_right*ox, dir);
  677.  
  678.     self.punchangle_x = -2;
  679. };
  680.  
  681.  
  682.  
  683. .float hit_z;
  684. void() spike_touch =
  685. {
  686. local float rand;
  687.     if (other == self.owner)
  688.         return;
  689.  
  690.     if (other.solid == SOLID_TRIGGER)
  691.         return;    // trigger field, do nothing
  692.  
  693.     if (pointcontents(self.origin) == CONTENT_SKY)
  694.     {
  695.         remove(self);
  696.         return;
  697.     }
  698.     
  699. // hit something that bleeds
  700.     if (other.takedamage)
  701.     {
  702.         spawn_touchblood (9);
  703.         T_Damage (other, self, self.owner, 9);
  704.     }
  705.     else
  706.     {
  707.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  708.         
  709.         if (self.classname == "wizspike")
  710.             WriteByte (MSG_BROADCAST, TE_WIZSPIKE);
  711.         else if (self.classname == "knightspike")
  712.             WriteByte (MSG_BROADCAST, TE_KNIGHTSPIKE);
  713.         else
  714.             WriteByte (MSG_BROADCAST, TE_SPIKE);
  715.         WriteCoord (MSG_BROADCAST, self.origin_x);
  716.         WriteCoord (MSG_BROADCAST, self.origin_y);
  717.         WriteCoord (MSG_BROADCAST, self.origin_z);
  718.     }
  719.  
  720.     remove(self);
  721.  
  722. };
  723.  
  724. void() superspike_touch =
  725. {
  726. local float rand;
  727.     if (other == self.owner)
  728.         return;
  729.  
  730.     if (other.solid == SOLID_TRIGGER)
  731.         return;    // trigger field, do nothing
  732.  
  733.     if (pointcontents(self.origin) == CONTENT_SKY)
  734.     {
  735.         remove(self);
  736.         return;
  737.     }
  738.     
  739. // hit something that bleeds
  740.     if (other.takedamage)
  741.     {
  742.         spawn_touchblood (18);
  743.         T_Damage (other, self, self.owner, 18);
  744.     }
  745.     else
  746.     {
  747.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  748.         WriteByte (MSG_BROADCAST, TE_SUPERSPIKE);
  749.         WriteCoord (MSG_BROADCAST, self.origin_x);
  750.         WriteCoord (MSG_BROADCAST, self.origin_y);
  751.         WriteCoord (MSG_BROADCAST, self.origin_z);
  752.     }
  753.  
  754.     remove(self);
  755.  
  756. };
  757.  
  758.  
  759. /*
  760. ===============================================================================
  761.  
  762. PLAYER WEAPON USE
  763.  
  764. ===============================================================================
  765. */
  766.  
  767. void() W_SetCurrentAmmo =
  768. {
  769.     player_run ();        // get out of any weapon firing states
  770.  
  771.     self.items = self.items - ( self.items & (IT_SHELLS | IT_NAILS | IT_ROCKETS | IT_CELLS) );
  772.     
  773.     if (self.weapon == IT_AXE)
  774.     {
  775.         self.currentammo = 0;
  776.         self.weaponmodel = "progs/v_axe.mdl";
  777.         self.weaponframe = 0;
  778.     }
  779.     else if (self.weapon == IT_SHOTGUN)
  780.     {
  781.         self.currentammo = self.ammo_shells;
  782.         self.weaponmodel = "progs/v_shot.mdl";
  783.         self.weaponframe = 0;
  784.         self.items = self.items | IT_SHELLS;
  785.     }
  786.     else if (self.weapon == IT_SUPER_SHOTGUN)
  787.     {
  788.         self.currentammo = self.ammo_shells;
  789.         self.weaponmodel = "progs/v_shot2.mdl";
  790.         self.weaponframe = 0;
  791.         self.items = self.items | IT_SHELLS;
  792.     }
  793.     else if (self.weapon == IT_NAILGUN)
  794.     {
  795.         self.currentammo = self.ammo_nails;
  796.         self.weaponmodel = "progs/v_nail.mdl";
  797.         self.weaponframe = 0;
  798.         self.items = self.items | IT_NAILS;
  799.     }
  800.     else if (self.weapon == IT_SUPER_NAILGUN)
  801.     {
  802.         self.currentammo = self.ammo_nails;
  803.         self.weaponmodel = "progs/v_nail2.mdl";
  804.         self.weaponframe = 0;
  805.         self.items = self.items | IT_NAILS;
  806.     }
  807.     else if (self.weapon == IT_GRENADE_LAUNCHER)
  808.     {
  809.         self.currentammo = self.ammo_rockets;
  810.         self.weaponmodel = "progs/v_rock.mdl";
  811.         self.weaponframe = 0;
  812.         self.items = self.items | IT_ROCKETS;
  813.     }
  814.     else if (self.weapon == IT_ROCKET_LAUNCHER)
  815.     {
  816.         self.currentammo = self.ammo_rockets;
  817.         self.weaponmodel = "progs/v_rock2.mdl";
  818.         self.weaponframe = 0;
  819.         self.items = self.items | IT_ROCKETS;
  820.     }
  821.     else if (self.weapon == IT_LIGHTNING)
  822.     {
  823.         self.currentammo = self.ammo_cells;
  824.         self.weaponmodel = "progs/v_light.mdl";
  825.         self.weaponframe = 0;
  826.         self.items = self.items | IT_CELLS;
  827.     }
  828.     else
  829.     {
  830.         self.currentammo = 0;
  831.         self.weaponmodel = "";
  832.         self.weaponframe = 0;
  833.     }
  834. };
  835.  
  836. float() W_BestWeapon =
  837. {
  838.     local    float    it;
  839.     
  840.     it = self.items;
  841.  
  842.     if(self.ammo_cells >= 1 && (it & IT_LIGHTNING) )
  843.         return IT_LIGHTNING;
  844.     else if(self.ammo_nails >= 2 && (it & IT_SUPER_NAILGUN) )
  845.         return IT_SUPER_NAILGUN;
  846.     else if(self.ammo_shells >= 2 && (it & IT_SUPER_SHOTGUN) )
  847.         return IT_SUPER_SHOTGUN;
  848.     else if(self.ammo_nails >= 1 && (it & IT_NAILGUN) )
  849.         return IT_NAILGUN;
  850.     else if(self.ammo_shells >= 1 && (it & IT_SHOTGUN) )
  851.         return IT_SHOTGUN;
  852.         
  853. /*
  854.     if(self.ammo_rockets >= 1 && (it & IT_ROCKET_LAUNCHER) )
  855.         return IT_ROCKET_LAUNCHER;
  856.     else if(self.ammo_rockets >= 1 && (it & IT_GRENADE_LAUNCHER) )
  857.         return IT_GRENADE_LAUNCHER;
  858.  
  859. */
  860.  
  861.     return IT_AXE;
  862. };
  863.  
  864. float() W_CheckNoAmmo =
  865. {
  866.     if (self.currentammo > 0)
  867.         return TRUE;
  868.  
  869.     if (self.weapon == IT_AXE)
  870.         return TRUE;
  871.     
  872.     self.weapon = W_BestWeapon ();
  873.  
  874.     W_SetCurrentAmmo ();
  875.     
  876. // drop the weapon down
  877.     return FALSE;
  878. };
  879.  
  880. /*
  881. ============
  882. W_Attack
  883.  
  884. An attack impulse can be triggered now
  885. ============
  886. */
  887. void()    player_axe1;
  888. void()    player_axeb1;
  889. void()    player_axec1;
  890. void()    player_axed1;
  891. void()    player_shot1;
  892. void()    player_nail1;
  893. void()    player_light1;
  894. void()    player_rocket1;
  895.  
  896. void() W_Attack =
  897. {
  898.     local    float    r;
  899.  
  900.     if (!W_CheckNoAmmo ())
  901.         return;
  902.  
  903.     makevectors    (self.v_angle);            // calculate forward angle for velocity
  904.     self.show_hostile = time + 1;    // wake monsters up
  905.  
  906.     if (self.weapon == IT_AXE)
  907.     {
  908.         sound (self, CHAN_WEAPON, "weapons/ax1.wav", 1, ATTN_NORM);
  909.         r = random();
  910.         if (r < 0.25)
  911.             player_axe1 ();
  912.         else if (r<0.5)
  913.             player_axeb1 ();
  914.         else if (r<0.75)
  915.             player_axec1 ();
  916.         else
  917.             player_axed1 ();
  918.         self.attack_finished = time + 0.5;
  919.     }
  920.     else if (self.weapon == IT_SHOTGUN)
  921.     {
  922.         player_shot1 ();
  923.         W_FireShotgun ();
  924.         self.attack_finished = time + 0.5;
  925.     }
  926.     else if (self.weapon == IT_SUPER_SHOTGUN)
  927.     {
  928.         player_shot1 ();
  929.         W_FireSuperShotgun ();
  930.         self.attack_finished = time + 0.7;
  931.     }
  932.     else if (self.weapon == IT_NAILGUN)
  933.     {
  934.         player_nail1 ();
  935.     }
  936.     else if (self.weapon == IT_SUPER_NAILGUN)
  937.     {
  938.         player_nail1 ();
  939.     }
  940.     else if (self.weapon == IT_GRENADE_LAUNCHER)
  941.     {
  942.         player_rocket1();
  943.         W_FireGrenade();
  944.         self.attack_finished = time + 0.6;
  945.     }
  946.     else if (self.weapon == IT_ROCKET_LAUNCHER)
  947.     {
  948.         player_rocket1();
  949.         W_FireRocket();
  950.         self.attack_finished = time + 0.8;
  951.     }
  952.     else if (self.weapon == IT_LIGHTNING)
  953.     {
  954.         player_light1();
  955.         self.attack_finished = time + 0.1;
  956.         sound (self, CHAN_AUTO, "weapons/lstart.wav", 1, ATTN_NORM);
  957.     }
  958. };
  959.  
  960. /*
  961. ============
  962. W_ChangeWeapon
  963.  
  964. ============
  965. */
  966. void() W_ChangeWeapon =
  967. {
  968.     local    float    it, am, fl;
  969.     
  970.     it = self.items;
  971.     am = 0;
  972.     
  973.     if (self.impulse == 1)
  974.     {
  975.         fl = IT_AXE;
  976.     }
  977.     else if (self.impulse == 2)
  978.     {
  979.         fl = IT_SHOTGUN;
  980.         if (self.ammo_shells < 1)
  981.             am = 1;
  982.     }
  983.     else if (self.impulse == 3)
  984.     {
  985.         fl = IT_SUPER_SHOTGUN;
  986.         if (self.ammo_shells < 2)
  987.             am = 1;
  988.     }        
  989.     else if (self.impulse == 4)
  990.     {
  991.         fl = IT_NAILGUN;
  992.         if (self.ammo_nails < 1)
  993.             am = 1;
  994.     }
  995.     else if (self.impulse == 5)
  996.     {
  997.         fl = IT_SUPER_NAILGUN;
  998.         if (self.ammo_nails < 2)
  999.             am = 1;
  1000.     }
  1001.     else if (self.impulse == 6)
  1002.     {
  1003.         fl = IT_GRENADE_LAUNCHER;
  1004.         if (self.ammo_rockets < 1)
  1005.             am = 1;
  1006.     }
  1007.     else if (self.impulse == 7)
  1008.     {
  1009.         fl = IT_ROCKET_LAUNCHER;
  1010.         if (self.ammo_rockets < 1)
  1011.             am = 1;
  1012.     }
  1013.     else if (self.impulse == 8)
  1014.     {
  1015.         fl = IT_LIGHTNING;
  1016.         if (self.ammo_cells < 1)
  1017.             am = 1;
  1018.     }
  1019.  
  1020.     self.impulse = 0;
  1021.     
  1022.     if (!(self.items & fl))
  1023.     {    // don't have the weapon or the ammo
  1024.         sprint (self, "no weapon.\n");
  1025.         return;
  1026.     }
  1027.     
  1028.     if (am)
  1029.     {    // don't have the ammo
  1030.         sprint (self, "not enough ammo.\n");
  1031.         return;
  1032.     }
  1033.  
  1034. //
  1035. // set weapon, set ammo
  1036. //
  1037.     self.weapon = fl;        
  1038.     W_SetCurrentAmmo ();
  1039. };
  1040.  
  1041. /*
  1042. ============
  1043. CheatCommand
  1044. ============
  1045. */
  1046. void() CheatCommand =
  1047. {
  1048.     if (deathmatch || coop)
  1049.         return;
  1050.  
  1051.     self.ammo_rockets = 100;
  1052.     self.ammo_nails = 200;
  1053.     self.ammo_shells = 100;
  1054.     self.items = self.items | 
  1055.         IT_AXE |
  1056.         IT_SHOTGUN |
  1057.         IT_SUPER_SHOTGUN |
  1058.         IT_NAILGUN |
  1059.         IT_SUPER_NAILGUN |
  1060.         IT_GRENADE_LAUNCHER |
  1061.         IT_ROCKET_LAUNCHER |
  1062.         IT_KEY1 | IT_KEY2;
  1063.  
  1064.     self.ammo_cells = 200;
  1065.     self.items = self.items | IT_LIGHTNING;
  1066.  
  1067.     self.weapon = IT_ROCKET_LAUNCHER;
  1068.     self.impulse = 0;
  1069.     W_SetCurrentAmmo ();
  1070. };
  1071.  
  1072. /*
  1073. ============
  1074. CycleWeaponCommand
  1075.  
  1076. Go to the next weapon with ammo
  1077. ============
  1078. */
  1079. void() CycleWeaponCommand =
  1080. {
  1081.     local    float    it, am;
  1082.     
  1083.     it = self.items;
  1084.     self.impulse = 0;
  1085.     
  1086.     while (1)
  1087.     {
  1088.         am = 0;
  1089.  
  1090.         if (self.weapon == IT_LIGHTNING)
  1091.         {
  1092.             self.weapon = IT_AXE;
  1093.         }
  1094.         else if (self.weapon == IT_AXE)
  1095.         {
  1096.             self.weapon = IT_SHOTGUN;
  1097.             if (self.ammo_shells < 1)
  1098.                 am = 1;
  1099.         }
  1100.         else if (self.weapon == IT_SHOTGUN)
  1101.         {
  1102.             self.weapon = IT_SUPER_SHOTGUN;
  1103.             if (self.ammo_shells < 2)
  1104.                 am = 1;
  1105.         }        
  1106.         else if (self.weapon == IT_SUPER_SHOTGUN)
  1107.         {
  1108.             self.weapon = IT_NAILGUN;
  1109.             if (self.ammo_nails < 1)
  1110.                 am = 1;
  1111.         }
  1112.         else if (self.weapon == IT_NAILGUN)
  1113.         {
  1114.             self.weapon = IT_SUPER_NAILGUN;
  1115.             if (self.ammo_nails < 2)
  1116.                 am = 1;
  1117.         }
  1118.         else if (self.weapon == IT_SUPER_NAILGUN)
  1119.         {
  1120.             self.weapon = IT_GRENADE_LAUNCHER;
  1121.             if (self.ammo_rockets < 1)
  1122.                 am = 1;
  1123.         }
  1124.         else if (self.weapon == IT_GRENADE_LAUNCHER)
  1125.         {
  1126.             self.weapon = IT_ROCKET_LAUNCHER;
  1127.             if (self.ammo_rockets < 1)
  1128.                 am = 1;
  1129.         }
  1130.         else if (self.weapon == IT_ROCKET_LAUNCHER)
  1131.         {
  1132.             self.weapon = IT_LIGHTNING;
  1133.             if (self.ammo_cells < 1)
  1134.                 am = 1;
  1135.         }
  1136.     
  1137.         if ( (self.items & self.weapon) && am == 0)
  1138.         {
  1139.             W_SetCurrentAmmo ();
  1140.             return;
  1141.         }
  1142.     }
  1143.  
  1144. };
  1145.  
  1146. /*
  1147. ============
  1148. ServerflagsCommand
  1149.  
  1150. Just for development
  1151. ============
  1152. */
  1153. void() ServerflagsCommand =
  1154. {
  1155.     serverflags = serverflags * 2 + 1;
  1156. };
  1157.  
  1158. void() QuadCheat =
  1159. {
  1160.     if (deathmatch || coop)
  1161.         return;
  1162.     self.super_time = 1;
  1163.     self.super_damage_finished = time + 30;
  1164.     self.items = self.items | IT_QUAD;
  1165.     dprint ("quad cheat\n");
  1166. };
  1167.  
  1168. /*
  1169. ============
  1170. ImpulseCommands
  1171.  
  1172. ============
  1173. */
  1174. void() ImpulseCommands =
  1175. {
  1176.     if (self.impulse >= 1 && self.impulse <= 8)
  1177.         W_ChangeWeapon ();
  1178.  
  1179.     if (self.impulse == 9)
  1180.         CheatCommand ();
  1181.     if (self.impulse == 10)
  1182.         CycleWeaponCommand ();
  1183.     if (self.impulse == 11)
  1184.         ServerflagsCommand ();
  1185.  
  1186.     if (self.impulse == 255)
  1187.         QuadCheat ();
  1188.         
  1189.     self.impulse = 0;
  1190. };
  1191.  
  1192. /*
  1193. ============
  1194. W_WeaponFrame
  1195.  
  1196. Called every frame so impulse events can be handled as well as possible
  1197. ============
  1198. */
  1199. void() W_WeaponFrame =
  1200. {
  1201.     if (time < self.attack_finished)
  1202.         return;
  1203.  
  1204.     ImpulseCommands ();
  1205.     
  1206. // check for attack
  1207.     if (self.button0)
  1208.     {
  1209.         SuperDamageSound ();
  1210.         W_Attack ();
  1211.     }
  1212. };
  1213.  
  1214. /*
  1215. ========
  1216. SuperDamageSound
  1217.  
  1218. Plays sound if needed
  1219. ========
  1220. */
  1221. void() SuperDamageSound =
  1222. {
  1223.     if (self.super_damage_finished > time)
  1224.     {
  1225.         if (self.super_sound < time)
  1226.         {
  1227.             self.super_sound = time + 1;
  1228.             sound (self, CHAN_BODY, "items/damage3.wav", 1, ATTN_NORM);
  1229.         }
  1230.     }
  1231.     return;
  1232. };
  1233.  
  1234.  
  1235.